EWS API -- "The move or copy operation failed" for a specific email

Hi,

I'm working on a console application that is using EWS Managed API to connect to a mailbox and process emails.  After processing has completed for an email, the program calls the API's move() on the EmailMessage to move it to another folder.

During our testing, the move has been working just fine but we recently encountered one specific email that does not move.  We think that it is something intrinsic about the email itself that will not allow it to be moved on the exchange server.  We get the following exception message (relevant parts of stack-trace included):

"The move or copy operation failed"

StackTrace:

at Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()

   at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()

   at Microsoft.Exchange.WebServices.Data.ExchangeService.MoveItem(ItemId itemId, FolderId destinationFolderId)

   at Microsoft.Exchange.WebServices.Data.Item.Move(FolderId destinationFolderId)

All other emails are moving just fine.  Nothing seems strange about the email.  It just has one .png image attachment.  I can open that attachment fine.  We are processing an outlook 365 mailbox, and I tried moving the email to my local outlook mailbox and processing it there and that works.  So it must be something on the exchange server that doesn't like this particular email.   We thought something could be locking it on the server temporarily, but when we tried again on the server, the move failed again with the same exception.  What do you think?  The code that does the move is included below, in case you can see any issue there.  Thanks!

Here's the function I have to move an email item to a specified folder (a subfolder under Inbox)  

Private Sub MoveToFolder(email As Item, folderName As String)

            ' Moves an email to the specified folder

            Dim folderView As New FolderView(100)
            folderView.PropertySet = New PropertySet(BasePropertySet.IdOnly)
            folderView.PropertySet.Add(FolderSchema.DisplayName)
            folderView.Traversal = FolderTraversal.Deep
            Dim findFolderResults As FindFoldersResults = email.Service.FindFolders(WellKnownFolderName.Inbox, folderView)

            Dim destFolder As Folder = findFolderResults.Where(Function(f As Folder) f.DisplayName = folderName) _
                                                        .FirstOrDefault()
            If destFolder Is Nothing Then

                ' If the folder doesn't exist, create it

                destFolder = New Folder(email.Service)
                With destFolder
                    .DisplayName = folderName
                    .Save(parentFolderName:=WellKnownFolderName.Inbox)
                End With
            End If

            Dim emailMessage As EmailMessage = DirectCast(email, EmailMessage)
            emailMessage.Move(destFolder.Id)

        End Sub

Thank you!

May 14th, 2015 11:04am

I forgot to mention that the email does have an empty body...

But that shouldn't be the issue as we have been able to move other emails that have empty bodies

Free Windows Admin Tool Kit Click here and download it now
May 14th, 2015 11:06am

Can you move it with Outlook or OWA?
May 14th, 2015 1:17pm

Yes, we are able to manually move it from the Outlook 365 inbox
Free Windows Admin Tool Kit Click here and download it now
May 14th, 2015 2:01pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics